export default {
  state: {
    // 主题颜色
    themeColor: JSON.parse(localStorage.getItem('themeColor') || '"#409EFF"'),
    // 导航栏收缩状态
    collapse: false,
    // 当前用户
    user: JSON.parse(sessionStorage.getItem('user') || '{}'),
    // 菜单路由是否已经加载
    menuRouteLoaded: false,
    // 路由
    routers: JSON.parse(sessionStorage.getItem('routers') || '[]'),
    // 菜单
    menus: JSON.parse(sessionStorage.getItem('menus') || '[]'),
    // 权限
    perms: JSON.parse(sessionStorage.getItem('perms') || '[]'),
    // 配置信息
    configLoading: false,
    config: JSON.parse(sessionStorage.getItem('config') || '{}'),
    typeList: JSON.parse(sessionStorage.getItem('typeList') || '{}')
  },
  getters: {
  },
  mutations: {
    // 改变收缩状态
    onCollapse (state) {
      state.collapse = !state.collapse
    },
    // 改变主题颜色
    setThemeColor (state, themeColor) {
      state.themeColor = themeColor
      localStorage.setItem('themeColor', JSON.stringify(themeColor))
    },
    // 加载配置信息
    loadConfig (state, data) {
      state.config = data.config
      state.typeList = data.typeList
      sessionStorage.setItem('config', JSON.stringify(data.config))
      sessionStorage.setItem('typeList', JSON.stringify(data.typeList))
    },
    configLoading (state, data) {
      state.configLoading = data
    },
    // 改变菜单和路由的加载状态
    menuRouteLoaded (state, menuRouteLoaded) {
      state.menuRouteLoaded = menuRouteLoaded
    },
    // 登录操作
    login (state, data) {
      state.user = data.user
      state.menuRouteLoaded = false
      state.routers = data.routers
      state.menus = data.menus
      state.perms = data.perms
      sessionStorage.setItem('user', JSON.stringify(data.user))
      sessionStorage.setItem('routers', JSON.stringify(data.routers))
      sessionStorage.setItem('menus', JSON.stringify(data.menus))
      sessionStorage.setItem('perms', JSON.stringify(data.perms))
    },
    // 登出操作
    logout (state) {
      state.menuRouteLoaded = false
      state.user = {}
      sessionStorage.removeItem('user')
      state.routers = []
      sessionStorage.removeItem('routers')
      state.menus = []
      sessionStorage.removeItem('menus')
      state.perms = []
      sessionStorage.removeItem('perms')
    }
  },
  actions: {
  }
}
